import DataCenter from "../GlobalData/DataCenter";

export default class mainScene extends Laya.Script {
    
    constructor() { super(); }
    private start_btn:Laya.Button
    private rank1_btn:Laya.Button
    private voice_btn:Laya.Button
    private un_voice_btn:Laya.Button      //关闭音乐
    private aniDuration:number            //Tween动画时长

    onEnable(): void {
        //初始化变量
        this.initParams()
        //入场动画
        this.enterAni()
        //初始化绑定事件
        this.initEvent()
    }

   /**初始化绑定事件 */
   initEvent(){
    //给开始按钮绑定事件
    this.start_btn.on(Laya.Event.CLICK,this,this.onStartGame)
    //给排行榜按钮绑定事件
    this.rank1_btn.on(Laya.Event.CLICK,this,this.onRank)
    //给声音按钮绑定事件
    this.voice_btn.on(Laya.Event.CLICK,this,this.onSound)
    //给关闭声音按钮绑定事件
    this.un_voice_btn.on(Laya.Event.CLICK,this,this.onSound)

}

    onStartGame(){
        //跳转场景
        Laya.Scene.open("select_scene.scene")
    }

    onRank(){
        Laya.Scene.open("rank_scene.scene")
    }

    onSound(){
        if(this.voice_btn.visible == true)
        {
            this.voice_btn.visible=false;
            Laya.SoundManager.stopMusic()
        }
        else
        {
            this.voice_btn.visible=true;
        }
        if(this.un_voice_btn.visible == true)
        {
            this.un_voice_btn.visible=false;
            Laya.SoundManager.playMusic("music/bg1.mp3",0)
        }
        else
        {
            this.un_voice_btn.visible=true;
        }
    }

    /**入场动画 */
    enterAni(){
        Laya.Tween.from(
            this.start_btn,
            {y:-174},
            this.aniDuration,
            Laya.Ease.strongInOut
        )

        Laya.Tween.from(
            this.rank1_btn,
            {y:720},
            this.aniDuration,
            Laya.Ease.strongInOut
        )

        Laya.Tween.from(
            this.voice_btn,
            {y:720},
            this.aniDuration,
            Laya.Ease.strongInOut
        )
    }

    /**初始化变量 */
    initParams()
    {
        //动画时长 
        this.aniDuration=550
        //获取开始按钮节点
        this.start_btn=this.owner.getChildByName('start')as Laya.Button
        //获取排行榜节点
        this.rank1_btn=this.owner.getChildByName('rank')as Laya.Button
        //获取声音节点
        this.voice_btn=this.owner.getChildByName('voice')as Laya.Button
        //获取关闭声音按钮节点
        this.un_voice_btn=this.owner.getChildByName('un_voice')as Laya.Button
    }

    onDisable(): void {
    }
}